<%@page import="com.grom.po.Department"%>
<%@page import="com.grom.service.DepartmentService"%>
<%@page import="com.grom.util.SecurityUtil"%>
<%@page import="com.grom.po.GcmsUser"%>
<%@page import="java.util.List"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" type="text/css" href="<%=request.getContextPath() %>/js/themes/default/easyui.css">
<link rel="stylesheet" type="text/css" href="<%=request.getContextPath() %>/js/themes/icon.css">
<script type="text/javascript" src="<%=request.getContextPath() %>/js/jquery-1.6.min.js"></script>
<script type="text/javascript" src="<%=request.getContextPath() %>/js/jquery.easyui.min.js"></script>

<script type="text/javascript">
$(function(){
	$('#loginInfoEdit').dialog({  
	    title : 'Brand 录入',  
	    modal: true,  
	    collapsible : true,    
	    resizable : true   
	});  
	$('#loginInfoEdit').dialog('close');
});


function showAddDialog(){
	$('input').each(function(){
		$(this).val('');
	});
	$('select').each(function(){
		$(this).val('');
	});
	$('#loginInfoEdit').dialog('open');
}

function loginInfoEdit(){
	$('brandForm').submit();
	$('#loginInfoEdit').dialog('close');
}

function viewDetail(){
	var itemId =  $('#tt').datagrid('getSelected').itemid;
	$.ajax({
	    url: '<%=request.getContextPath()%>/GcmsUserAction/getDetail.do?itemid='+itemId,
	    type: 'GET',
	    timeout: 1000,
	    error: function(){
	        alert('Error getting response!');
	    },
	    success: function(json){
	        var user = eval(json);
	        $('#ID').val(user.ID);
	        $('#userName').val(user.userName);
	        $('#password').val(user.password);
	        $('#remark').val(user.remark);
	        $('#departmentID').val(user.departmentID);
			$('#loginInfoEdit').dialog('open');
	    }
	});
}

function doDelete(){
	var itemId =  $('#tt').datagrid('getSelected').itemid;
	if (itemId){  
        $.messager.confirm('Confirm','Are you sure you want to remove this user?',function(r){  
            if (r){  
				$('#deleteId').val(itemId);
				$('#deleteForm').submit();
            }  
        });  
    } 
}
function doSearch(){
	$('#searchForm').submit();
}
</script>
</head>
<body>
<div style="display: none;">
	<form name="deleteForm" id="deleteForm" action="<%=request.getContextPath() %>/GcmsUserAction/doDelete.do">
		<input type="text" name="deleteId" id="deleteId"/>
	</form>
</div>
<div style="font-size: 10px;">
	<form id="searchForm" name="searchForm" action="<%=request.getContextPath() %>/GcmsUserAction/conditionSelect.do" method="post">
      <label>用户名：</label>  
      <input type="text" name="userName_s" id="userName_s" ></input>  
      <label>remark：</label>  
      <input type="text" name="remark_s" id="remark_s" ></input>  
      <a href="#" class="easyui-linkbutton" iconCls="icon-search" plain="true" onclick="doSearch()">search</a>
    </form>
</div>
<table id="tt" class="easyui-datagrid"  singleSelect="true"
        title="DataGrid with Toolbar" iconCls="icon-save"  
        toolbar="#tb">  
    <thead>  
        <tr>  
            <th field="itemid" width="80">Item ID</th>  
            <th field="userName" width="80">用户名</th>  
            <th field="password" width="80" align="right">密码</th>  
            <th field="remark" width="80" align="right">备注</th>   
        </tr>  
    </thead>  
    <tbody>     
    	<%
    		List<GcmsUser> allUsers = (List<GcmsUser>)request.getAttribute("allUsers");
    		for(GcmsUser user : allUsers){
    	%>
        <tr>                             
            <td><%=user.getID() %></td>              
            <td><%=user.getUserName() %></td>              
            <td><%=user.getPassword() %></td>              
            <td><%=user.getRemark() %></td>                          
        </tr>  
    	<%
    		}
    	%>                         
    </tbody>
</table>  
<div id="tb">  
   <%
	if(session.getAttribute("USER")!=null){
%>
    <a href="#" class="easyui-linkbutton" iconCls="icon-add" plain="true" onclick="showAddDialog()">Add</a>  
    <a href="#" class="easyui-linkbutton" iconCls="icon-cut" plain="true" onclick="viewDetail()">view/update</a>  
    <a href="#" class="easyui-linkbutton" iconCls="icon-remove" plain="true" onclick="doDelete()">Delete</a> 
    <a href="#" class="easyui-linkbutton" iconCls="icon-back" plain="true" onclick="javascript:alert('我觉着这个翻页不实用，设置下条件吧！')">pre page</a> 
    <a href="#" class="easyui-linkbutton" iconCls="icon-back" plain="true" onclick="javascript:alert('我觉着这个翻页不实用，设置下条件吧！')">next page</a> 
<%
	}
%>
</div>  


<!-- 编辑 -->  
<div id="loginInfoEdit"  
    style="padding: 5px; width: 300px; height: 250px;">  
    <h5 id="loginInfoEdit_message" style="color: red;"></h5>  
    <div class="ToolTip_Form" id="table_loginInfoEdit" onkeydown="if(event.keyCode==13){loginInfoEdit();}">  
       <form id="userForm" name="userForm" action="<%=request.getContextPath() %>/GcmsUserAction/doSave.do" method="post">
       <input type="hidden" name="ID" id="ID" value="" />
       <ul>    
            <li>  
                <label>用户名：</label>  
                <input type="text" class="easyui-validatebox" name="userName" id="userName" maxlength="20" required="true"></input>  
            </li>  
            <li>  
                <label>密码：</label>  
                <input type="text" class="easyui-validatebox" name="password" id="password" maxlength="20" required="true"></input>  
            </li> 
            <li>  
                <label>备注：</label>  
                <input type="text" class="easyui-validatebox" name="remark" id="remark" maxlength="20" ></input>  
            </li> 
            <li>  
                <label>所属部门：</label>  
                <select id="departmentID" name="departmentID">
                	<option value="">不关联</option>
                	<%
                		List<Department> allDep = DepartmentService.instance.getAllDepartment();
                		for(Department depart : allDep){
                			%>
                			<option value="<%=depart.getID() %>"><%=depart.getDepartmentName() %></option>
                			<%
                		}
                	%>
                </select>
            </li> 
            <li>  
             	<a href="#" class="easyui-linkbutton" onclick="$('#userForm').submit();">保存</a>
            	<a href="#" class="easyui-linkbutton" onclick="$('#loginInfoEdit').dialog('close');">放弃操作</a>
            </li>  
        </ul>  
       </form>
    </div>  
</div>  
</body>
</html>